散佈圖
import numpy as np
import matplotlib.pyplot as plt
x = np.random.rand(100) * 10
y = np.random.randint(1, 101, 100)
plt.scatter(x, y, marker='s')
plt.xlabel('xlabel_value')
plt.ylabel('ylabel_value')
plt.title('Scatter chart')
plt.show()
直方圖
import matplotlib.pyplot as plt
import numpy as np
import random
fig, ax = plt.subplots()
x = np.arange(1, 11, 1)
rdata = []
for i in range(50):
n = random.randint(1, 10)
rdata.append(n)
rdata.sort()
print(rdata)
plt.hist(rdata)
plt.title('Histogram')
plt.xticks(x)
plt.show()